package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.AliyunSms;
import com.stylefeng.guns.modular.pay.service.IAliyunSmsService;

/**
 * 短信服务控制器
 *
 * @author fengshuonan
 * @Date 2018-09-07 15:34:31
 */
@Controller
@RequestMapping("/aliyunSms")
public class AliyunSmsController extends BaseController {

    private String PREFIX = "/pay/aliyunSms/";

    @Autowired
    private IAliyunSmsService aliyunSmsService;

    /**
     * 跳转到短信服务首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "aliyunSms.html";
    }

    /**
     * 跳转到添加短信服务
     */
    @RequestMapping("/aliyunSms_add")
    public String aliyunSmsAdd() {
        return PREFIX + "aliyunSms_add.html";
    }

    /**
     * 跳转到修改短信服务
     */
    @RequestMapping("/aliyunSms_update/{aliyunSmsId}")
    public String aliyunSmsUpdate(@PathVariable Integer aliyunSmsId, Model model) {
        AliyunSms aliyunSms = aliyunSmsService.selectById(aliyunSmsId);
        model.addAttribute("item",aliyunSms);
        LogObjectHolder.me().set(aliyunSms);
        return PREFIX + "aliyunSms_edit.html";
    }

    /**
     * 获取短信服务列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return aliyunSmsService.selectList(null);
    }

    /**
     * 新增短信服务
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AliyunSms aliyunSms) {
        aliyunSmsService.insert(aliyunSms);
        return SUCCESS_TIP;
    }

    /**
     * 删除短信服务
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer aliyunSmsId) {
        aliyunSmsService.deleteById(aliyunSmsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改短信服务
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AliyunSms aliyunSms) {
        aliyunSmsService.updateById(aliyunSms);
        return SUCCESS_TIP;
    }

    /**
     * 短信服务详情
     */
    @RequestMapping(value = "/detail/{aliyunSmsId}")
    @ResponseBody
    public Object detail(@PathVariable("aliyunSmsId") Integer aliyunSmsId) {
        return aliyunSmsService.selectById(aliyunSmsId);
    }
}
